import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';

export default function getJobHistoryData(pk_psnjob) {

    const {
        humanResourceOrganizationValue: {
            refpk
        }
    } = this.state;

    const {
        modal: {
            show
        },
        table: {
            setAllTableData
        } 
    } = this.props;

    let postData = {
        pk_org: refpk,
        func_type: 2,
        pk_psnjob
    };

    return proFetch({
        url: '/nccloud/hrhi/psndoc/PsndocQueryJobHistroyAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success) {
                show('jobHistory');
                setAllTableData('hi_psnjob_history', res.data.currentJobs.hi_psnjob);
                if(res.data.histroyJobs) {
                    this.setState({
                        showHistoryTable: true
                    }, () => {
                        setAllTableData('hi_psnjob_history_down', res.data.histroyJobs.hi_psnjob);
                    });
                    
                }
                else {
                    this.setState({
                        showHistoryTable: false
                    }, () => {
                        setAllTableData('hi_psnjob_history_down', {rows:[]});
                    });
                }
            }
        });
}
